﻿#region Using directives
using System;
using System.Windows;
using UltimateNavigationFramework;
using UltimateNavigationFramework.Loaders;
using Microsoft.Practices.Unity;
#endregion

namespace UltimateReferenceImplementation
{
    public class Bootstrapper : UltimateUnityBootstrapper
    {
        #region Create Module Catalog
        protected override Microsoft.Practices.Prism.Modularity.IModuleCatalog CreateModuleCatalog()
        {
            return Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri("ModuleCatalog.xaml", UriKind.Relative));
        } 
        #endregion

        #region Create view catalog
        /// <summary>
        /// Custom View Catalog Implementation
        /// </summary>
        /// <returns></returns>
        protected override IViewCatalog CreateViewCatalog()
        {
            return ViewCatalog.CreateFromXaml(new Uri("ViewCatalog.xaml", UriKind.Relative));
        }
        #endregion

        #region Configure Container
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            // Register any other services here
        } 
        #endregion

        #region Create shell
        protected override DependencyObject CreateShell()
        {
            var viewLoader = this.Container.Resolve<IUltimateViewLoadingService>();

            viewLoader.LoadView("ShellView", (view, success, error) =>
            {
                if (view != null)
                {
                    this.Shell = view as UIElement;
                    App.Current.RootVisual = view as UIElement;
                }
                else
                    throw error;
            });
            return null;
        }
        #endregion
    }
}
